package TestArray;

public class ArrayDemo4 {
    public static void main(String[] args) {
        //冒泡排序,对一组整数有小到大排序
        int[] arr={34,53,12,32,56,17};
        //排序前的数组
        System.out.println("排序前的数组:");
        for (int n:arr) {
            System.out.print(n+" ");
        }
        System.out.println();
        int temp;
        for (int i=0;i<arr.length;i++){
            for (int j=0;j< arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    temp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=temp;
                }
            }
        }
        System.out.println("排序后的数组:");
        for (int n:arr) {
            System.out.print(n+" ");
        }
    }
}
